var e, t = (e = require("@vant/weapp/toast/toast")) && e.__esModule ? e : {
    default: e
};

var a = getApp(), o = require("../../utils/config");

Page({
    data: {
        image: o.resourceRoot + "pdf.png",
        themeColor: a.globalData.themeColor,
        filePath: "",
        invoiceNum: "",
        loadingHidden: !1,
        loadinginfo: "",
        showButtons: !1
    },
    onLoad: function(e) {
        this.setData({
            filePath: decodeURIComponent(e.pdfUrl),
            invoiceNum: e.invoiceNum
        }), this.downLoad();
    },
    viewReport: function() {
        "" == this.data.filePath && (0, t.default)({
            message: "请先下载发票",
            duration: 5e3
        }), wx.openDocument({
            filePath: this.data.filePath,
            showMenu: !0,
            success: function(e) {}
        });
    },
    shareReport: function() {
        "" == this.data.filePath && (0, t.default)({
            message: "请先下载发票",
            duration: 5e3
        }), wx.shareFileMessage({
            filePath: this.data.filePath,
            success: function() {},
            fail: console.error
        });
    },
    downLoad: function() {
        var e = this, t = wx.env.USER_DATA_PATH + "/" + e.data.invoiceNum + ".pdf";
        wx.downloadFile({
            url: e.data.filePath,
            filePath: t,
            success: function(a) {
                e.setData({
                    loadingHidden: !0,
                    loadinginfo: "发票加载中..."
                }), 200 === a.statusCode && e.setData({
                    filePath: t,
                    showButtons: !0
                });
            },
            fail: function(e) {
                console.log(444, e);
            }
        });
    }
});